#include "api_twitter.h"



char* get_resource (char *resource, char *access_token_key, char *access_token_secret){
	char *postarg = NULL;
    char *req_url;
    char *reply;
	
	req_url = oauth_sign_url2(resource, &postarg, OA_HMAC, NULL, CONSUMER_KEY, CONSUMER_SECRET, access_token_key, access_token_secret);
    reply = oauth_http_post(req_url,postarg);

	if(DEBUG_MODE) {
		debug_print (MODULE_NAME,"get_resource","requested url",req_url);
		
	}
	
	if(req_url) free(req_url);
	if(postarg) free(postarg);
  	if(reply) return reply;

	return NULL;
}
/*
char * get_image_name (char *url){
	int length = strlen(url);
	int i,j=0;
	char *filename = (char *) malloc (sizeof(char) * MAX_FILENAME_LENGTH);
	char *filename2 = (char *) malloc (sizeof(char) * MAX_FILENAME_LENGTH);
	for(i=length-1;url[i]!='/';(i--,j++)){
		filename[j]=url[i];
	}
	filename[j]='\0';
    j=strlen(filename)-1;
	for(i=0;i<strlen(filename);(i++,j--)){
		filename2[j]=filename[i];
	}	
	return filename2;
}

void get_profile_image(char *url){
	
  CURL *curl;
  CURLcode res;
	
  k_file *image = (k_file *) malloc (sizeof(k_file));
  char *filename = get_image_name(url);
  strcpy(image->filename,filename);
  image->data = NULL;
 
  curl_global_init(CURL_GLOBAL_DEFAULT);
 
  curl = curl_easy_init();
	
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL,url);

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data_to_file);

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, image);
 
    res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
 
    if(CURLE_OK != res) {
      fprintf(stderr, "curl told us %d\n", res);
    }
  }
 
  if(image->data)
    fclose(image->data);
  curl_global_cleanup();

}*/